package com.hdu.pyl.service.similarity;

import com.hdu.pyl.pojo.NewScoreByUser;
import com.hdu.pyl.pojo.News;
import com.hdu.pyl.service.basic.NewScoreByUserServiceImpl;
import com.hdu.pyl.util.MathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 基于余弦相似度的评估
 */
@Service
public class UserNewsCosineSimilarityImpl implements UserNewsSimilarity {

    @Autowired
    private NewScoreByUserServiceImpl newScoreByUserService;

    @Override
    public List<News> recommendNews(Integer limit, Integer userId) {
        return null;
    }

    @Override
    public Double UserScoreNews(Integer userId, Integer newsId) {
        NewScoreByUser newScoreByUser = newScoreByUserService.findByUserId(userId);
        Integer time = newScoreByUser.getSeconds();
        Integer v = newScoreByUser.getViewNum();
        Integer size = newScoreByUser.getSize();
        if (null == size) {
            return null;
        }
        Double score = (MathUtil.Sigmoid(time / size * v) - 0.5) * 2;
        return score;
    }

}
